<template>
  <div class="search-module">
    <el-input v-model="searchVal" size="large" @keydown.enter="search()">
      <template #prepend>
        <el-select v-model="searchType" placeholder="选择" style="width: 110px">
          <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value" />
        </el-select>
      </template>
      <template #append>
        <el-button @click="search()" size="large">搜索</el-button>
      </template>
    </el-input>
  </div>
</template>

<script lang="ts" setup>
import { defineExpose, ref } from 'vue'
const searchVal = ref('')
const searchType = ref('pubmed')

const options = [
  {
    value: 'pubmed',
    label: 'pubmed'
  },
  {
    value: 'ClinicalTrials',
    label: 'ClinicalTrials'
  },
  {
    value: 'beta ClinicalTrials',
    label: 'beta ClinicalTrials'
  },
  {
    value: 'chictr',
    label: 'chictr'
  },
  {
    value: 'wanfang',
    label: '万方'
  },
  {
    value: 'baidu',
    label: '百度'
  }
]

const search = (word?: string) => {
  let url = ''
  const q = encodeURIComponent(word || searchVal.value)
  switch (searchType.value) {
    case 'pubmed':
      url = `https://pubmed.ncbi.nlm.nih.gov/?term=${q}`
      break
    case 'ClinicalTrials':
      url = `https://clinicaltrials.gov/search?patient=${q}`
      break
    case 'beta ClinicalTrials':
      url = `https://beta.clinicaltrials.gov/search?patient=${q}`
      break
    case 'chictr':
      url = `http://www.chictr.org.cn/searchproj.aspx?title=${q}`
      break
    case 'wanfang':
      url = `https://s.wanfangdata.com.cn/paper?q==${q}`
      break
    case 'baidu':
      url = `https://www.baidu.com/s?ie=UTF-8&wd=${q}`
      break
  }

  window.open(url)
}

defineExpose({
  search
})
</script>
<style lang="scss" scoped>
</style>
